<template>
  <view class="content">
    <view class="title">子组件B</view>
    <view class="b-box">
      CompA组件传进来的值：
      <text class="intent-text-box">{{result}}</text>
    </view>
    <view class="b-box" style="margin: 10rpx;">
      <text>回传值：</text>
      <input type="text" v-model="callbackValue" style="color: yellow;" />
      <button @click="sendOutside()" size="mini">回传</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      result: '',
      callbackValue: '0595-2788888'
    }
  },
  created() {
    // 监听CompA传递的事件
    uni.$on('compAData', (val) => {
      this.result = val;
    });
  },
  methods: {
    sendOutside() {
      // 向父组件回传值
      this.$emit('callBackFun', this.callbackValue);
    }
  }
}
</script>

<style scoped>
.content {
  background: green;
  padding: 20rpx;
  margin: 20rpx 0;
}
.title {
  font-size: 32rpx;
  margin-bottom: 10rpx;
}
.b-box {
  margin: 5rpx 0;
}
.intent-text-box {
  background: blue;
  color: white;
  padding: 2rpx 5rpx;
}
</style>